import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP

# 导入密文
with open("cipher_text.txt", "r", encoding="utf-8") as fp:
    cipher_text = fp.read()


# print(cipher_text)
cipher_bytes = cipher_text.encode("utf-8")
# base64解码
base_cipher_bytes = base64.b64decode(cipher_bytes)
# print(base_cipher_bytes)

# 导入秘钥

with open("private_key.pem", "rb") as fp:
    private_key = fp.read()

private_key_obj = RSA.import_key(private_key)  # 创建秘钥对象

pkcs1 = PKCS1_OAEP.new(private_key_obj)  # 创建解密对象
content_bytes = pkcs1.decrypt(base_cipher_bytes)  # 解密

# print(content_bytes)
content = content_bytes.decode("utf-8")  # 对二进制内容进行解码，获得明文
print(content)